#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <fstream>
#include <iostream>
#include <armadillo>
#include <iomanip>
//#include "H5Cpp.h"


//using namespace cv;
using namespace std;
using namespace arma;

#include "grass_pointsII_def.hpp"
#include "grass_pointsII_impl.hpp"


#include "clustering_def.hpp"
#include "clustering_impl.hpp"


///Comentarios Noviembre 12:
//Taken from grassmann-summarisation.
//Using my UCSD-annotated dataset.



/*
Taken from "CLUSTERING ON GRASSMANN MANIFOLDS VIA KERNEL EMBEDDING
WITH APPLICATION TO ACTION ANALYSIS"
*/

/*Nov 15
 * Kkmeans updated.. Improved version. 
 * Returning One segment (Point) per cluster (the closest segment to the centroid)
 */

/*Nov20
 * Mision abortada -> No funciona.
 * Ver proximo proyecto usando Riemmannian Manifolds
 * */


int
main(int argc, char** argv)
{
  
  std::string videos_list;
  videos_list = "/home/johanna/codes-svn/myUCSD_clustering/my_UCSD/"; // before videos_list 
  
  field<std::string> vi_names;
  vi_names.load("video_names.txt");
  
  vi_names.print("vi_names");

  
  field<std::string> frame_list;
  
  ///ojo
  double vec_size = 60*38; // images size ///ojo
   //maximum p is the dimension of the original data. In this case = 60*38 = 2280
  int p = 20; // Number of consecutive frames!!! NOOOOOOOOOOOO
  
  /*
  for (uword i = 0 ; i < vi_names.n_rows; ++i)// videos_list.n_rows
  {
    cout << "i= " << i << endl;
    
    std::stringstream one_video;
    one_video << videos_list <<  vi_names(i,0) <<"/";
    
    std::string video = one_video.str();
    
    
    std::stringstream path_frames;
    path_frames << video << "/list.txt";
    cout << "path_frames "<< path_frames.str() << endl;
    
    frame_list.load(path_frames.str()); // se debe cargar por carpeta, tienen diferente # de frames.
      
    cout << "Doing for " << video << endl;
    
    grassmann_points grass_pt(video, frame_list, vec_size, p);///ojo
    
    std::stringstream points_list;
    points_list << "./grass_points/Gp_" << vi_names(i,0) << ".dat";
    
    cout << "saving in " << points_list.str() << endl;
    std::string Gpoint= points_list.str();

    grass_pt.save_GrassPoints(Gpoint);
    cout << "saved "<< endl;

  //Guardar hacer un ciclo por video y guardar el nombre, para solo calcular una vez. Mirar donde dice ojo en grass_points
  }*/
  
  
  

  
  int summ_percentage = 20;
  for (uword i = 0 ; i < 1; ++i)// vi_names.n_rows
  {
    
    std::stringstream point_name;
    point_name << "./grass_points/Gp_" << vi_names(i,0) <<".dat";
    
    std::string name_Gpoint = point_name .str();
    
    cout << "name_Gpoint: " << name_Gpoint << endl;
    clustering_grass grass(name_Gpoint);
    
    std::stringstream Ker_name;
    Ker_name <<"./Kernel_matrix/Ker_" << vi_names(i,0) << ".dat";     
    cout << "To load from "<<  Ker_name.str()<< endl;
    
    std::stringstream resul;
    resul <<"./Results/Perce="<< summ_percentage << "_" << vi_names(i,0) << ".dat";     
    
    std::stringstream GT;
    GT <<"./GT/new_Gp_annotations_" << vi_names(i,0) << ".dat";     // Ground Truth per Grassmann Point
    cout << "GT= " << GT.str() << endl;
   
    //getchar();
    grass.euc_cluster(Ker_name.str(), resul.str(),GT.str(), summ_percentage);
    //grass.ker_cluster(Ker_name.str(), resul.str(),GT.str(), sum_percentage);
    cout << "************************" << endl;
    
  }
  
  
  return 0;
  
}


/* Previous main - This project comes from ker_grassmann_clustering
//Taken from "CLUSTERING ON GRASSMANN MANIFOLDS VIA KERNEL EMBEDDING
//WITH APPLICATION TO ACTION ANALYSIS"

int
main(int argc, char** argv)
{
  
  
  
  
  
  //INPUTS for Grassmann Clustering
  field<std::string> action_list;
  action_list.load("action_list.txt");
  //action_list.print("actions");
  //cout << "# Acciones: " << action_list.n_rows << endl;
  
  field<std::string> person_list;
  person_list.load("person_list.txt");
  //cout << "# Personas: " << person_list.n_rows << endl;
   
  //double vec_size = cvImage.rows*cvImage.rows;
  double vec_size = 20*20; //Image size 20x20
  //maximum p is the dimension of the original data. In this case = 20*20
  int p = 20; // Order's subspace to calculate the Grassmann Points
  
  //maximum m is the number of points or samples (#actions * #people).
  int m = 50; // For the Grassmann Clustering as per Fig. 1 in Sareh's paper (Clustering...)
  
  //end INPUTS

  
  clustering_grass grass(person_list,  action_list, vec_size, p);
  grass.cluster();  // Using Kernel Kmeans
  //grass.cluster(m); // Using Euclidean Kmeans. Not working
  
  
  return 0;
  
}

 
 
 */


